All Questions
88 questions
0votes
3answers
196views
How to edit a string matching a pattern in a specific field on the condition another string is not present on the same line
I need to edit the string "NA" to "Na" only if it is in the 6th field of a file. I can currently achieve this with: awk '{gsub("NA","Na",$6)}1' $filename ...
1vote
3answers
363views
awk print between lines when "/" is part of the name
I need to print lines between those that contain a "/" in the name. I tried with: awk '/+SOLUTION/ESTIMATES/,/-SOLUTION/ESTIMATES/' $F > fil$F and awk '/+SOLUTION"/"ESTIMATES/,/...
0votes
4answers
845views
how to print first word from a string with multiple words without space?
I have a shell script to print appimage filenames inside a folder like this #! /bin/bash Dir="$HOME/Applications/" Dir2="$HOME/Downloads/" cd -P "$Dir" for f in *....
3votes
1answer
2kviews
How to print leading zeros (padding) in awk?
I am trying to print 99.11111 as 099.11 in AWK. I have tried the following variations without success. $ awk '{printf ("%000.2f\n", $1);}' <<< 99.111111 99.11 $ awk '{printf ("%...
0votes
1answer
794views
Quoting a string in output from awk
I am fetching a string from a file using awk as shown below. Now I would like to double quote it. Any support would be highly appreciated. awk -F',' '{print $(NF)}' sample.csv| tail +2 output: ...
0votes
0answers
17views
How to returns the correct character after manipulating the output of ps ax | grep [duplicate]
I would like to have some help writing a script (which should works on freebsd where I have sh as default) that should grab a precise character when I do a "ps ax | grep" command from the ...
0votes
1answer
4kviews
Awk substr index 0
I just discovered that substr() in awk accepts either 0 or 1 as the initial index in a string. I tested this in Gawk 5.1.0 and MacOS awk 20070501. awk 'BEGIN {print substr("abcd", 0, 1)}' ...
1vote
2answers
6kviews
split string using a substring as delimiter and get the later part
Here is my string LIBRARY_TRGT_CANV,CANV_MATCH<anything> I wish to get all the text after last occurance of our delimiter which is _TRGT_: Desired output: CANV,CANV_MATCH<anything> ------ ...
0votes
1answer
123views
Need help Formatting a file having key: value [duplicate]
I have a file having the below values: cat data.txt server1: 'calv' server2: 'anot' log: '/u/log/1' server3: 'calv' server4: 'anot' server5: 'secd' server6: 'calv' LIB_TRGT_calv,anot: '/tmp/hello.txt' ...
-1votes
3answers
332views
Need to format text file and update based of key value format
I have a file having the below values: cat data.txt server1: calv server2: anot log: /u/log/1 server3: calv server4: anot server5: secd server6: calv LIB_TRGT_calv,anot: /tmp/hello.txt LIB_TRGT_secd: /...
-1votes
5answers
883views
How to make sure that the last character of each line of a file ends with single quote character
I have a file which has several lines. I wish to update the file while making sure that the last visible character of each line of the file is a single quote '. In case not, then we should add the ...
0votes
1answer
1kviews
How to add single quote at the end of ONLY the last line of a file [duplicate]
I want a non-perl solution where I should be able to append a single quote ' at the last visible (non-escape characters) line of a file and save it back to the file. cat example.txt var1: 'funn' var2: ...
1vote
2answers
966views
Remove duplicates of specific line keeping only the first appearance of each without touching other unspecified duplicates
I'm trying to edit a text file containing several duplicates. The goal is to keep only the first match of a string and remove the rest duplicate lines of the same string. In the example file * Title 1 ...
3votes
2answers
10kviews
How to search for a string in a very large file with very long lines?
It turns out I was accidentally using grep wrong yesterday. I just checked my bash history and saw what I was executing: grep search-string-here -f large-file-with-long-lines.txt And that was what ...
1vote
2answers
73views
Increment mountpoint name with awk
I am currently writing a script that makes mounting of LUKS devices easier. In the script I do have a default mountpoint name (data_1), - however, if a mountpoint like that already exists, I want to ...